non deterministic algorithm